package Items.Top01.Lease;

import java.util.Scanner;

public class Manager {
    Scanner in=new Scanner(System.in);
    private int pos = 0;//记录车辆数量
    Car[] cars = new Car[20];

    public int getPos() {
        return pos;
    }

    public void setPos(int pos) {
        this.pos = pos;
    }

    public Manager() {
        cars[0] = new LittleCar("京NY28588", "宝马X6    ", 800, "轿车", false, 4);
        cars[1] = new LittleCar("京CNY3284", "宝马550i  ", 600, "轿车", false, 4);
        cars[2] = new LittleCar("京NT37465", "别克林荫大道", 300, "轿车", false, 4);
        cars[3] = new LittleCar("京NT96968", "别克GL8   ", 600, "轿车", true, 4);

        cars[4] = new PassengerCar("京6566754", "金杯   ", 800, 16, false, "大客");
        cars[5] = new PassengerCar("京8696997", "金龙   ", 800, 16, true, "大客");
        cars[6] = new PassengerCar("京9696996", "金杯   ", 1500, 34, false, "大客");
        cars[7] = new PassengerCar("京8696998", "金龙   ", 1500, 34, true, "大客");
        pos = 8;
    }

    public void showCarList() {//显示车辆信息
        for (int i = 0; i < cars.length; i++) {
            if (cars[i] == null)
                continue;
            System.out.println(cars[i].toString());
        }
    }

    public void lease() {//租借
        System.out.println("请输入要租赁的车型(大客\t轿车)");
        String carType=in.next();
        for (int i = 0; i < getPos(); i++) {
            if (!cars[i].isLease()) {
                continue;
            }
            if (cars[i].getModel().equals(carType))
                System.out.println(cars[i]);
        }
        System.out.println("请输入要租借的车牌号：");
        String carNum=in.next();
        System.out.println("请输入租借天数:");
        int days=in.nextInt();
        for (int i=0;i<getPos();i++){
            if (cars[i].isLease()){
                continue;
            }
            if (cars[i].getCarNum().equals(carNum)){
                System.out.println("租借成功");
                System.out.println("您租借的是"+cars[i].getCarNum()+"\t"+cars[i].getBrand()+"\t"+cars[i].getModel()+"\t"+cars[i].getSeatNum());
                System.out.println("价格为"+cars[i].countRent(days));
                cars[i].setLease(true);
            }
        }
    }

    public  void  add(){//添加
        System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
        System.out.println("请输入添加的车辆信息");
        System.out.println();
        System.out.println("请输入车牌号：");
        String carnum=in.next();
        System.out.println("请输入车辆型号：");
        String brand=in.next();
        System.out.println("请输入座位数：");
        int seat=in.nextInt();
        System.out.println("请设定此车租金：");
        double price=in.nextDouble();
        System.out.println("请输入要采购车型(大客\t轿车)");
        for (;;){
            System.out.println("请选择");
            String model=in.next();
            if (model.equals("大客")){
                cars[pos]=new PassengerCar(carnum,brand,price,seat,false,"大客");
                pos++;
                System.out.println("已添加采购车辆信息");
                return;
            }else if (model.equals("轿车")){
                cars[pos]=new LittleCar(carnum,brand,price,"轿车",false,seat);
                pos++;
                System.out.println("已添加采购车辆信息");
                return;
            }
        }
    }

    public void delCar(){
        showCarList();
        System.out.println("请输入要报废车辆牌照");
        String carnum=in.next();
        for (int i=0;i<pos;i++){
            if (cars[i].getCarNum().equals(carnum)){
                cars[i]=null;
                for (int j=i;j<pos;j++){
                    cars[j]=cars[j+1];
                    cars[pos-1]=null;
                }
                pos--;
                System.out.println("报废成功");
                return;
            }

        }
        System.out.println("报废失败，车辆信息有误");
    }

    public void returnCar(){
        System.out.println("请输入要归还的车辆牌照");
        String carnum=in.next();
        for (int i=0;i<pos;i++){
            if (cars[i].getCarNum().equals(carnum)){
                cars[i].setLease(false);
                System.out.println("还车成功");
                return;
            }
        }
        System.out.println("还车失败，请检查所输入牌照是否正确");
    }
    }


